package com.lovo.pis.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.pis.constant.MessageCode;
import com.lovo.pis.dto.PageBean;
import com.lovo.pis.dto.SellCarGoodsBean;
import com.lovo.pis.service.ISellCarGoodsService;
import com.lovo.pis.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/sellCarGoods")
public class SellCarGoodsController {

    @Autowired
    ISellCarGoodsService sellCarGoodsService;

    //根据购物车id分页查询所有
    @RequestMapping("/queryAll")
    public IPage<SellCarGoodsBean> queryAllBuyCarGoods(@RequestBody PageBean<SellCarGoodsBean> pageInfo){
        return sellCarGoodsService.queryAllBuyCarGoods(pageInfo);
    }

    @RequestMapping("/querySumPrice")
    public double getSumPrice(int carId){
        return sellCarGoodsService.getSumPrice(carId);
    }

    //根据购物车id和销售商品id修改销售商品出库数量
    @RequestMapping("/change")
    public JsonResult<Integer> changeItem(int carId, int id, int number){
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setData(sellCarGoodsService.changeItem(carId,id,number));
        return jsonResult;
    }

    //移除销售商品
    @RequestMapping("/remove")
    public JsonResult removeById(int carId,int id){
        JsonResult jsonResult = new JsonResult<>();
        sellCarGoodsService.removeById(carId,id);
        return jsonResult;
    }

    //添加销售商品
    @RequestMapping("/add")
    public JsonResult addBuyCarGoods(int id,int carId){
        JsonResult jsonResult = new JsonResult<>();
        sellCarGoodsService.addBuyCarGoods(id,carId);
        return jsonResult;
    }

}
